home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byt86aug.arc
/
MATHREC.ARC
/
PALIND.BAS
< prev
next >
Wrap
BASIC Source File
|
1980-01-01
|
2KB
|
69 lines
10 REM --------< Palindromic Sums Routine >--------
20 REM --------< Bob Kurosaka >--------
30 REM
40 SP$=" " :REM One space inside quotes
50 D$="0123456789"
60 YES=(1=1)
70 DIM A(100) :REM A() holds the the digits.
80 CLS
90 PRINT "Program generates sequences that end
in palindromes."
100 PRINT
110 PRINT "Lower limit (>10) and upper limit ";
120 INPUT LL, UL
130 LL=ABS(INT(LL))
140 UL=ABS(INT(UL))
150 IF LL<10 THEN 110
160 FOR N=LL TO UL
170 SP=0 :REM SP counts the steps before a cycle
180 REM
190 REM Break up the term into its component digits
200 M=N :REM Make a copy of latest term
210 D=1 :REM D = no. of digits
220 T=INT(M/10) :REM T = no. of "Tens" in M
230 A(D)=M-10*T :REM Store rightmost digit in
array A
240 IF T<>0 THEN D=D+1: M=T: GOTO 220
250 ODD=ABS((INT(D/2)<>D/2)) :REM Even or odd
no. of digits?
260 REM
270 REM Print the latest term
280 FOR I=D TO 1 STEP -1
290 PRINT MID$(D$,A(I)+1,1);
300 NEXT I
310 PRINT SP$;
320 REM
330 REM Check for palindrome
340 FOR I=1 TO D/2
350 PL=(A(I)=A(D-I+1))
360 IF NOT PL THEN I=D/2 :REM Exit from loop if
no. is not a pal.
370 NEXT I
380 IF PL THEN 580
390 REM
400 REM Add each digit to its reverse image
counterpart
410 FOR I=1 TO D/2+ODD
420 A(I)=A(I)+A(D-I+1)
430 A(D-I+1)=A(I)
440 NEXT I
450 REM Check for carry
460 FOR I=1 TO D
470 IF A(I)<10 THEN 500
480 A(I)=A(I)-10
490 A(I+1)=A(I+1)+1
500 NEXT I
510 IF A(D+1)=0 THEN 540
520 D=D+1
530 ODD=ABS((INT(D/2)<>D/2))
540 SP=SP+1
550 GOTO 280
560 REM
570 REM Indicate that a cycle has been found
580 PRINT "* at step "; SP
590 FOR I=1 TO D
600 A(I)=0
610 NEXT I
620 NEXT N
630 END